package redisdb

import (
	"github.com/gomodule/redigo/redis"
	"leaf/db/yorick"
	"leaf/log"
	"time"
)

func Run_redis(addr string) {
	pool := &redis.Pool{
		MaxActive: 888,
		//最大闲置连接数
		// Maximum number of idle connections in the pool.
		MaxIdle: 20,
		//闲置连接的超时时间
		// Close connections after remaining idle for this duration. If the value
		// is zero, then idle connections are not closed. Applications should set
		// the timeout to a value less than the server's timeout.
		IdleTimeout: time.Second * 100,
		//定义拨号获得连接的函数
		// Dial is an application supplied function for creating and configuring a
		// connection.
		//
		// The connection returned from Dial must not be in a special state
		// (subscribed to pubsub channel, transaction started, ...).
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", addr)
		},
	}
	defer pool.Close()
	yorick.System.RedisClient = pool
	log.Success("开启Redis成功 %s", addr)
}
